﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;

namespace ABC.PoItems
{
    public class PoItemsHelper
    {
        /// <summary>
        /// Function Purpose: Used to get a collection of some parts info that are attached to a WO. 
        /// </summary>
        /// <param name="woNum"></param>
        /// <returns></returns>
        public static List<Part> getWOParts(long woNum)
        {
            List<Part> list = new List<Part>();
            string sqlString = "select DESC, PART, INDATE, STATE, LOC from tabPOitem where PORDTYPE = 'WO' and ORDFOR = " + woNum;
            OleDbCommand command = new OleDbCommand(sqlString, ABC.Database.DataBaseConnection.MyConn);
            OleDbDataReader areader = command.ExecuteReader();
            while (areader.Read())
            {
                Part parts = new Part();
                if (areader["INDATE"] != DBNull.Value)
                    parts.dInDate = Convert.ToDateTime(areader["INDATE"]);
                parts.sPartDescription = areader["DESC"].ToString();
                parts.sPartLocation = areader["LOC"].ToString();
                parts.sPartNumber = areader["PART"].ToString();
                parts.sState = areader["STATE"].ToString();
                list.Add(parts);

            }
            areader.Close();            
            return list;
        }
       
    }

    public struct Part
    {
        public string sPartNumber;
        public string sPartDescription;
        public DateTime dInDate;
        public string sState;
        public string sPartLocation;

    }

}
